package com.lanou.service.impl;

import com.lanou.service.OrderService;
import com.lanou.utils.HttpClientUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by QuChao on 2018/12/5
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Value("${ORDER_ADDRESS_LIST_URL}")
    private String ORDER_ADDRESS_LIST_URL;

    @Value("${ORDER_ADDRESS_DEL_URL}")
    private String ORDER_ADDRESS_DEL_URL;

    @Value("${ORDER_ADDRESS_ADD_URL}")
    private String ORDER_ADDRESS_ADD_URL;

    @Value("${ORDER_ADDRESS_UPDATE_URL}")
    private String ORDER_ADDRESS_UPDATE_URL;

    @Value("${ORDER_ORDER_ADD_URL}")
    private String ORDER_ORDER_ADD_URL;

    @Value("${ORDER_ORDER_DETAIL_URL}")
    private String ORDER_ORDER_DETAIL_URL;

    @Override
    public Map<String, Object> getAddress(Map<String, Object> map) {
        return HttpClientUtils.getObject(ORDER_ADDRESS_LIST_URL + map.get("userId"), Map.class);
    }

    @Override
    public Map<String, Object> deleteAddress(Map<String, Object> map) {
        return HttpClientUtils.getObject(ORDER_ADDRESS_DEL_URL + map.get("addressId"), Map.class);
    }

    @Override
    public Map<String, Object> addAddress(Map<String, Object> map) {
        return HttpClientUtils.getObject(ORDER_ADDRESS_ADD_URL + map.get("####"), Map.class);
    }

    @Override
    public Map<String, Object> updateAddress(Map<String, Object> map) {
        return HttpClientUtils.getObject(ORDER_ADDRESS_UPDATE_URL + map.get("#$#####"), Map.class);
    }

    @Override
    public Map<String, Object> addOrder(Map<String, Object> map) {
        return HttpClientUtils.getObject(ORDER_ORDER_ADD_URL + map.get("####"), Map.class);
    }

    @Override
    public Map<String, Object> detail(Long orderId) {
        return HttpClientUtils.getObject(ORDER_ORDER_DETAIL_URL + "?orderId=" + orderId, Map.class);
    }
}
